import pymysql


def insert():
    conn = pymysql.connect(host='192.168.1.5', port=3306,
                           user='root', password='25840',
                           db='school',
                           charset='utf8')
    # print(conn)
    try:
        with conn.cursor() as c:
            c.execute('insert into tb_student(user_id,name,gender,class,company_add) values(2021201659,"赵毅佳",0,'
                      '"2021级商务英语一班","新疆昌吉市中山南路新街口商务广场");')
            result = c.fetchall()
            result == 1
            print('done')
            conn.commit()
    except:
        print('exist')
        conn.rollback()
    finally:
        conn.close()


if __name__ == '__main__':
    insert()


def add_col():
    with pymysql.connect(user='root', host='192.168.1.5',
                         passwd='25840', db='school', port=3306) as conn:
        # print(conn)
        try:
            with conn.cursor() as c:
                c.execute('update tb_student set col_name="经济管理学院" '
                          'where name="赵毅佳";')
                conn.commit()
                print('yes')

        except:
            print('no')
            conn.rollback()
        finally:
            with conn.cursor() as show:
                show.execute('select name, col_name from tb_student '
                             'where name="赵毅佳";')
                print(show.fetchall())


if __name__ == '__main__':
    add_col()
